package com.example.gateway.config;

import com.github.xiaoymin.knife4j.spring.gateway.Knife4jGatewayProperties;
import com.github.xiaoymin.knife4j.spring.gateway.Knife4jGatewayProperties.Router;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@Configuration
public class Knife4jConfig {

    @Primary
    @Bean
    public Knife4jGatewayProperties knife4jGatewayProperties() {
        return new Knife4jGatewayProperties() {
            @Override
            public List<Router> getRoutes() {
                Router router = new Router();
                router.setOrder(0);
                router.setName("gateway");
                router.setServiceName("gateway");
                router.setUrl("/v3/api-docs");
                router.setContextPath("");

                Router router2 = new Router();
                router2.setOrder(1);
                router2.setName("user-service");
                router2.setServiceName("user-service");
                router2.setUrl("api/users/v3/api-docs");
                router2.setContextPath("/api/users");

                Router router3 = new Router();
//                router3.setOrder(1);
//                router3.setName("druid-route");
//                router3.setServiceName("druid-route");
//                router3.setUrl("/druid");
//                router3.setContextPath("");

                // 手动声明需要聚合的服务
                return Arrays.asList(
                        router,router2,router3
                );
            }
        };
    }
}